<div class="row" style="height:100%;">
	<div class="col-lg-12" style="border-right:1px solid #e6e6e6;padding-right:0px;">
		<h1 class="site-h1" style="background-color:#FFFFFF;">
			号码池<#if numberPoolList?? && numberPoolList.content??>（${numberPoolList.content?size}）</#if>
		</h1>
		<div class="layui-col-md12" >
			<div class="layui-card">
				<!--<form class="layui-form" action="/admin/callcenter/numberpool/index.html" data-message=false data-target="#callCenterContent" data-toggle="ajax-form">
					<input type="hidden" name="hostid" value="${pbxHost.id!''}" />
					<div class="layui-form-item form_type">
						<label class="layui-form-label">呼叫方向：</label>
						<div class="layui-input-inline">

						</div>
					</div>

					<div class="form_btns">
						<button class="form_submit" lay-submit lay-filter="*">查询</button>
						<button type="button" class="form_reset">重置</button>
					</div>
				</form>-->

				<div class="table_box " style="padding:5px;">
					<a  class="layui-btn layui-btn-sm layui-btn-normal"  data-type="add"><i class="layui-icon">&#xe654;</i>新增</a>
					<a  class="layui-btn layui-btn-sm layui-btn-normal" data-type="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
					<a  class="layui-btn layui-btn-sm layui-btn-danger" data-type="del"  title="删除"><i class="layui-icon">&#xe640;</i>删除</a>
					<table id="bigtable" lay-filter="bigtable"></table>
					<div class="row" id="page" style="text-align:center;"></div>
				</div>
				<!-- table_box -->
			</div>
		</div>
	</div>	
</div>

<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail" >详情</a>
</script>
<script>
	var layer ;
	var table;
	layui.use('form', function() {
		var form = layui.form;
		form.render();


		/*form.on('submit(*)', function(data){
			top.iframe = window.frameElement && window.frameElement.id || '';
			iframe =  window.frameElement && window.frameElement.id || '';
			return true;
		});*/
	});

	<#if msg?? && msg != ''>
	layer.alert('${msg!""}', {icon: 2});
	</#if>

	var laypage;

	layui.use(['table','layer','laypage'], function() {
		table = layui.table;
		layer = layui.layer;
		laypage = layui.laypage;

		table.render({
			elem: '#bigtable',
			skin:'line',
			cols: [
				[{
					type: 'checkbox'
				},
					{
						field: 'number',
						title: '号码'
					},{
					field: 'createTime',
					title: '创建时间'
				}/*,
					{
						title: '操作'
						, toolbar: '#barDemo',
						width:100
					}*/
				]
			],
			data: [
					<#if numberPoolList?? && numberPoolList.content?? && numberPoolList.content?size gt 0>
					<#list numberPoolList.content as callRate>
					{
						"number": "${callRate.number!''}",
						"id": "${callRate.id!''}",
						"createTime": "${callRate.createtime?string('yyyy-MM-dd HH:mm:ss')}",
					},
				</#list>
					</#if>
				],
							limit: 20
				});

		  laypage.render({
				elem: 'page'
				,pages: <#if numberPoolList??>${numberPoolList.totalPages}<#else>0</#if> //总页数
				,curr:<#if numberPoolList??>${numberPoolList.number+1}<#else>0</#if>
				,groups: 5 //连续显示分页数
				,jump:function(data , first){
					if(!first){
						location.href = "/admin/callcenter/numberpool/index.html?hostid=${pbxHost.id!''}&p="+data.curr ;
					}
				}
		   });


		var active = {
			add: function(){
				loadUrlWithAjax("/admin/callcenter/numberpool/add.html?hostid=${pbxHost.id!''}","新增号码",500,350);
			}
			,edit: function(){
				var data = table.checkStatus('bigtable').data;
				if(data && data.length == 1 ){
					loadUrlWithAjax("/admin/callcenter/numberpool/edit.html?id="+data[0].id,"编辑",500,350);
				}else{
					layer.alert("只能选择一条数据!", {icon: 2});
				}
			}
			,del: function(){ //验证是否全选
				var checkStatus = table.checkStatus('bigtable');
				var data = checkStatus.data;
				if(data.length > 0 ){
					top.layer.confirm("确认执行删除操作吗？删除操作同时会删除与分机绑定的相关数据", {icon: 3, title:'提示'}, function(index){
						top.layer.close(index);
						if(confirm){
							var params = "";
							for(var j=0;j<data.length;j++){
								params = params + "ids=" + data[j].id + "&";
							}
							//location.href = "/admin/callcenter/rate/delete.html?hostid=${pbxHost.hostId!''}&" + params;

							$.ajax({
								url:"/admin/callcenter/numberpool/delete.html?hostid=${pbxHost.id!''}&" + params,
								cache:false,
								success: function(data){
									top.layer.close(index);

									$("#callCenterContent").empty().html(data);
								},
								error:  function(xhr, type, s){
									if(xhr.getResponseHeader("emsg")){
										art.alert(xhr.getResponseHeader("emsg"));
									}
								}
							}).done(function(){

							});
						}
					})
				}else{
					layer.alert("请至少选择一条数据!", {icon: 2});
				}

			}
		};

		$('.table_box .layui-btn').on('click', function(){
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		$(".form_reset").click(function(){
			$("#number").val("");
			form.render();
		});

	});
</script>